<!-- 仓库调拨页面 -->
<template>
	<view class="">
		<newNavBar></newNavBar>
		<movable-area :style="{ height: swiperHeight + 'px' }" style="width: 100%;">
			<swiper :style="{ height: swiperHeight + 'px' }" :current="currentIndex" :indicator-dots="true"
				@change="changeSwiper">
				<swiper-item>
					<view style="background-color: #fff;">
						<scroll-view :style="{ height: swiperHeight + 'px' }" scroll-y="true">
							<uni-forms ref="baseForm" :modelValue="baseFormData" class="content" label-position="top">
								<uni-forms-item label="临时编码" name="tempCode" :labelWidth="labelWidth" required>
									<data-select-puls :readOnly="true" v-model="baseFormData.tempCode"
										:localdata="baseRange.tempCodeRange" @change="change($event,'temp')" />
								</uni-forms-item>
								<uni-forms-item v-show="isShowWare()" label="发生仓库" name="wareHouse"
									:labelWidth="labelWidth" required>
									<data-select-puls :disabled="baseDisabled" :clear="!baseDisabled"
										v-model="baseFormData.wareHouse" :localdata="baseRange.wareHouseRange"
										@change="change($event,'ware')" />
								</uni-forms-item>
								<uni-forms-item v-show="isShowTargetWare()" label="目标仓库" name="targetWareHouse"
									:labelWidth="labelWidth" required>
									<data-select-puls :disabled="baseDisabled" :clear="!baseDisabled"
										v-model="baseFormData.targetWareHouse" :localdata="baseRange.wareHouseRange"
										@change="change($event,'targetWare')" />
								</uni-forms-item>
								<uni-forms-item v-show="false" label="发生部门" name="operateDept" :labelWidth="labelWidth"
									required>
									<data-select-puls :disabled="baseDisabled" :clear="!baseDisabled"
										v-model="baseFormData.operateDept" :localdata="baseRange.depTypeRange"
										@change="change($event,'dept')" />
								</uni-forms-item>
								<uni-forms-item v-show="isShowWare()" label="出库类型" name="typeCode"
									:labelWidth="labelWidth" required>
									<data-select-puls :disabled="baseDisabled" :clear="!baseDisabled"
										v-model="baseFormData.typeCode" :localdata="baseRange.sdTypeRange"
										@change="change" />
								</uni-forms-item>
								<uni-forms-item v-show="isShowTargetWare()" label="入库类型" name="targetTypeCode"
									:labelWidth="labelWidth" required>
									<data-select-puls :disabled="baseDisabled" :clear="!baseDisabled"
										v-model="baseFormData.targetTypeCode" :localdata="baseRange.targetSdTypeRange"
										@change="change" />
								</uni-forms-item>
								<uni-forms-item v-if="pageCode=='pom'||pageCode=='pos'" label="关联单据号" name="orderCode"
									:labelWidth="labelWidth" required>
									<view class="form-item">
										<uni-easyinput v-model="baseFormData.orderCode" placeholder="请选择"
											suffixIcon="right" @iconClick="openCommon" />
									</view>
								</uni-forms-item>
								<uni-forms-item label="发生日期" name="happenDate" :labelWidth="labelWidth" required>
									<uni-datetime-picker :disabled="baseDisabled" type="date" :clear-icon="false"
										v-model="baseFormData.happenDate" />
								</uni-forms-item>
								<!-- 调拨单没有单据类型 -->
								<uni-forms-item v-show="false" label="单据类型" name="isBlue" :labelWidth="labelWidth"
									required>
									<uni-data-checkbox :disabled="baseDisabled"
										style="margin-top: 5px;margin-left: 14px;" :selectedColor="selectedColor"
										:selectedTextColor="selectedColor" v-model="baseFormData.isBlue"
										:localdata="blueList" @change="change" />
								</uni-forms-item>
								<uni-forms-item v-show="isShowPosition()" label="发生货位" name="goodsPosition"
									:labelWidth="labelWidth" required>
									<data-select-puls :disabled="baseDisabled" :clear="!baseDisabled"
										v-model="baseFormData.goodsPosition" :localdata="baseRange.goodsPositionRange"
										@change="change" />
								</uni-forms-item>
								<uni-forms-item v-show="isShowTargetPosition()" label="目标货位" name="targetGoodsPosition"
									:labelWidth="labelWidth" required>
									<data-select-puls  
										v-model="baseFormData.targetGoodsPosition"
										:localdata="baseRange.targetGoodsPositionRange" @change="change" />
								</uni-forms-item>
								<uni-forms-item label="条码号" name="scanBarCode" :labelWidth="labelWidth" required>
									<view class="form-item">
										<uni-easyinput type="text" v-model="scanBarCode" :focus="scanFouce"
											@focus="getFocus" placeholder="请输入条码号" @confirm="scanInput" />
										<uni-badge style="margin-left: 10px;" :customStyle="{background: '#42b983'}"
											:text="scanNumber" absolute="rightTop" size="small">
											<uni-icons type="scan" size="27" style="margin-left: 6px;"
												@click="iconClick" />
										</uni-badge>
									</view>
								</uni-forms-item>
								<uni-forms-item>
									<uni-easyinput disabled autoHeight type="textarea" maxlength="-1"
										v-model="returnMessage" />
								</uni-forms-item>
							</uni-forms>
						</scroll-view>
					</view>
				</swiper-item>

				<!-- 列表信息 -->
				<swiper-item>
					<!-- <view id="listTop" :style="{background: 'rgba(255, 255, 255,'+opacityValue+')' }"
						class="listTop fixedTop">
						<view v-for="(listItem,index) in sumList" :index="index" :key="index">
							<view style="margin: 10px;">
								<uni-row v-for="(litem,index) in listItem.list" :key="index">
									<uni-col v-for="(citem,index) in litem.content" :key="index"
										:span="getListContent(litem.content)">
										<view style="padding: 5px;">
											<text>{{citem.title}}: </text>
											<text style="color: #ff0000;">{{citem.value}}</text>
										</view>
									</uni-col>
								</uni-row>
							</view>
						</view>
						<view class="tab-bar-line"></view>
					</view> -->

					<listView :swiperHeight="swiperHeight" scrollY="true" @listScroll="listScroll"
						@scrolltolower="scrolltolower" :headData="headInfo" :listData="scanBarListInfo"
						:loadMore="loadMore" :loadStaus="loadStaus" :sumHeadData="sumHeadData"
						:sumListData="sumListData">
						<template v-slot="{ msg }">
							<view v-for="(listItem,index) in showBarMXList(msg)" :index="index" :key="index">
								<view style="background-color: #ffffff;">
									<uni-row v-for="(litem,rindex) in listItem.list" :key="rindex">
										<uni-col v-for="(citem,cindex) in litem.content" :key="cindex"
											:span="getListContent(litem.content)">
											<view style="padding: 5px;">
												<text v-if="citem.title" style="font-size: 11px;">{{citem.title}}:
												</text>

												<text
													:style="{'font-size':citem.fontSize!=undefined?citem.fontSize+'px':'15px','color':citem.color!=undefined?citem.color:'#686765'}">
													{{citem.value}}</text>

											</view>
										</uni-col>
									</uni-row>
								</view>
							</view>
						</template>
					</listView>
				</swiper-item>

			</swiper>
			<!-- 实现悬浮按钮的移动 -->
			<movable-view style="width: 80px;height: 80px;" :x="x+20" :y="y" direction="all">
				<view style="display: flex;justify-content: center;	background-color: #aaff7f; ">

					<uni-fab ref="fab" :pattern="pattern" :content="content" :horizontal="horizontal"
						:vertical="vertical" direction="vertical" @trigger="fadTrigger" />

				</view>
			</movable-view>
		</movable-area>
		<!-- <text>入库界面</text> -->

		<!-- 提示窗示例 -->
		<uni-popup ref="alertDialog" type="dialog">
			<commonDiaog></commonDiaog>
		</uni-popup>

	</view>
</template>

<script>
	import CommonInfo from '../business/CommonInfo.vue'
	import * as SystemJs from '../../common/system.js'
	import * as configJs from '../../common/config.js'

	export default {
		components: {
			CommonInfo
		},
		data() {
			return {
				pageCode: '',
				pageType: '',
				mainColor: '',
				//滑动区域的高度(单位px)
				swiperHeight: 0,
				//当前索引
				currentIndex: 0,
				labelWidth: '90', //label标签的宽度
				scanBarCode: '', //扫描条码号
				returnMessage: '', //返回结果
				scanFouce: false, //扫描输入框自动获取焦点
				buttonLoading: false, //提交按钮是否为等待状态
				windowWidth: 0,
				horizontal: 'right', //悬浮按钮的定位
				vertical: 'bottom',
				selectedColor: 'blue', //单选按钮默认的颜色
				listSumHeight: 0, //list列表中汇总框的高度
				showListSum: false, //是否显示顶部汇总信息栏
				loadMore: true, //是否显示加载更多
				loadStaus: 'noMore', //是否显示加载状态
				sumPages: 1, //列表总页数
				page: 1, //当前数据加载页
				opacityValue: '0', //列表顶部汇总页面的透明度
				//悬浮按钮进行移动
				x: 0,
				y: 0,
				old: {
					x: 0,
					y: 0
				},
				//悬浮按钮的样式设置
				pattern: {
					color: '#000',
					backgroundColor: '#fff',
					selectedColor: '#000',
					buttonColor: configJs.baseColor.mainTitleColor,
					iconColor: '#fff'
				},
				scanNumber: 0, //扫描的条码数量
				sumCount: 0,
				baseFormData: {
					tempCode: '',
					wareHouse: '', //发生仓库编码
					targetWareHouse: '', //目标仓库编码
					goodsPosition: '', //发生货位编码
					targetGoodsPosition: '', //目标货位编码
					operateDept: '', //部门编码
					deptName: '', //部门名称
					outOrderCode: '', //参照单据
					typeCode: '', //出库发生类型
					targetTypeCode: '', //入库发生类型
					isBlue: '1',
					happenDate: '',
					customCode: ''
				},
				baseRange: {
					tempCodeRange: [],
					wareHouseRange: [],
					targetWareHouseRange: [],
					sdTypeRange: [],
					targetSdTypeRange: [],
					depTypeRange: [],
					goodsPositionRange: [],
					targetGoodsPositionRange: []
				},
				baseDisabled: false, //基础信息是否可选择
				range: [{
						value: 0,
						text: "篮球"
					},
					{
						value: 1,
						text: "足球"
					},
					{
						value: 2,
						text: "游泳"
					}
				],
				localData: [{
					"value": "110000",
					"text": "北京市",
					"children": [{
						"value": "110105",
						"text": "朝阳区"
					}, {
						"value": "110108",
						"text": "海淀区"
					}],
				}],
				blueList: [{
					value: '1',
					text: '蓝单'
				}, {
					value: '0',
					text: '红单'
				}],
				//悬浮按钮中按钮的列表
				content: [{
						iconPath: '/static/add.png',
						selectedIconPath: '/static/add.png',
						text: '新增单据',
						code: 'add',
						active: false
					}, {
						iconPath: '/static/del.png',
						selectedIconPath: '/static/del.png',
						text: '删除单据',
						code: 'del',
						active: false
					},
					{
						iconPath: '/static/save.png',
						selectedIconPath: '/static/save.png',
						text: '保存单据',
						code: 'save',
						active: false
					}
				],
				headInfo: [],
				listInfo: [],
				scanBarListInfo: [],
				sumList: [],
				userInfo: {},
				sumHeadData: [],
				sumListData: [],
				barMxHeadData: [],
				barMxListData: [],
				noClick: true
			}
		},
		onShow() {
			//this.getBaseInfo();
			this.$nextTick(() => {
				uni.hideKeyboard()
			})
			// plus.key.hideSoftKeybord()
			// uni.hideKeyboard(); //隐藏软键盘
		},
		onLoad(res) {
			try {
				this.pageCode = res.pageCode;
				this.pageType = res.pageType;
				SystemJs.systemJs.showTitleBar(res.pageName, true)
				this.mainColor = configJs.baseColor.mainTitleColor;
				//设置默认日期
				this.baseFormData.happenDate = SystemJs.systemJs.getDate()
				//获取屏幕高度
				uni.getSystemInfo({
					success: (res) => {
						this.x = res.windowWidth * 0.7;
						this.y = res.windowHeight * 0.8
						this.windowWidth = res.windowWidth;
						var statusBar = res.statusBarHeight //状态栏高度
						//屏幕高度-状态栏高度-自定义导航栏高度
						this.swiperHeight = res.screenHeight - statusBar - 45
						// console.log('heightShow', this.swiperHeight)

					}
				})
				this.userInfo = configJs.getBaseInfo.getUserInfo();
				this.getBaseInfo();
			} catch (e) {
				SystemJs.httpUnit.uniToast(Json.stringify(e))
			}
			this.listInfo = [{
				list: [{
					content: [{
						title: "条码",
						value: '20221123114020'
					}]
				}, {
					content: [{
							title: "仓库",
							value: '成品库'
						},
						{
							title: "宽度",
							value: '122'
						}
					]
				}, {
					content: [{
						title: "长度",
						value: '123'
					}, {
						title: "重量",
						value: '200'
					}]
				}]
			}]
			// uni.hideKeyboard();
		},
		mounted() {
			// SystemJs.systemJs.getByIdHeight("listTop", this, 'listSumHeight');
			// this.listSumHeight=81;

			// uni.hideKeyboard()
			this.$nextTick(() => {
				uni.hideKeyboard()
			})
		},
		methods: {
			isShowWare() {
				var flag = true;
				if (this.pageCode) {
					if (this.pageCode.indexOf('cp') > 0) {
						flag = false;
					}
				}
				return flag;
			},
			isShowTargetWare() {
				var flag = true;
				if (this.pageCode) {
					if (this.pageCode.indexOf('ll') > 0) {
						flag = false;
					}
				}
				return flag;
			},
			isShowTargetPosition() {
				var flag = true;
				if (this.pageCode) {
					// if (this.pageCode.indexOf('cp') > 0) {
					// 	flag = false;
					// }
					if (this.pageCode.indexOf('ll') > 0) {
						flag = false;
					}
				}
				return flag;
			},
			isShowPosition() {
				var flag = false;
				// if (this.pageCode) {
				// 	if (this.pageCode.indexOf('cp') > 0) {
				// 		flag = false;
				// 	}
				// 	if (this.pageCode.indexOf('ll') > 0) {
				// 		flag = false;
				// 	}
				// }
				return flag;
			},
			/**
			 * 显示条码明细数据
			 * @param {Object} index
			 */
			showBarMXList(index) {
				var tempList = [];
				if (this.scanBarListInfo && this.scanBarListInfo.length > 0) {
					if (this.barMxListData && this.barMxListData.length > 0) {
						//获取该条码下list明细数据
						var objList = this.barMxListData[index];
						if (objList && objList.length > 0) {
							tempList = SystemJs.unitJs.createListItemInfo(this.barMxHeadData, objList);
						}
					}
				}
				return tempList;
			},
			/**
			 * 获取临时编码信息列表
			 */
			async getTemCodeInfo() {
				//获取单据临时编码信息
				this.baseRange.tempCodeRange = await configJs.getBaseInfo.getTempCode({
					inOutType: this.pageCode,
					operateType: this.pageType
				})
				this.baseFormData.tempCode = this.selectFirstRage(this.baseRange.tempCodeRange, []);
				if (this.baseRange.tempCodeRange.length > 0) {
					this.getSelectTempInfo(this.baseRange.tempCodeRange[0]);
				}
			},
			/**
			 * 获取货位信息
			 */
			async getGoodsPosition(wareHouse, goodsPosition = "") {
				//获取货位信息
				this.baseRange.goodsPositionRange = await configJs.getBaseInfo.getGoodsPosition({
					wareHouse: wareHouse
				})
				this.baseFormData.goodsPosition = this.selectFirstRage(this.baseRange.goodsPositionRange, []);
				if (!SystemJs.systemJs.IsEmpty(goodsPosition)) {
					this.baseFormData.goodsPosition = goodsPosition
				}
			},
			/**
			 * 获取目标货位信息
			 */
			async getTargetGoodsPosition(wareHouse, targetGoodsPosition = "") {
				//获取货位信息
				this.baseRange.targetGoodsPositionRange = await configJs.getBaseInfo.getGoodsPosition({
					wareHouse: wareHouse
				})
				this.baseFormData.targetGoodsPosition = this.selectFirstRage(this.baseRange.targetGoodsPositionRange,
					[]);
				if (!SystemJs.systemJs.IsEmpty(targetGoodsPosition)) {
					this.baseFormData.targetGoodsPosition = targetGoodsPosition
				}
			},
			/**
			 * 获取下拉框中基础信息
			 */
			async getBaseInfo() {
				
				//获取出入库默认仓库信息
				var defaultWareHouse = await configJs.getBaseInfo.getDefaultWareHouse()
				//获取仓库信息
				this.baseRange.wareHouseRange = await configJs.getBaseInfo.getWareHouse({
					inOutType: this.pageCode
				})
				this.baseFormData.wareHouse = this.selectFirstRage(this.baseRange.wareHouseRange, defaultWareHouse,
					"happen");
				// await this.getGoodsPosition(this.baseFormData.wareHouse)
				this.baseFormData.targetWareHouse = this.selectFirstRage(this.baseRange.wareHouseRange,
					defaultWareHouse, "target");
				console.log(this.baseFormData.wareHouse)
				await this.getTargetGoodsPosition(this.baseFormData.targetWareHouse)
				//获取出入库默认部门信息
				var defaultDepType = await configJs.getBaseInfo.getDefaultDepartment()
				//获取部门信息
				this.baseRange.depTypeRange = await configJs.getBaseInfo.getDepartment({
					inOutType: this.pageCode
				})
				this.baseFormData.operateDept = this.selectFirstRage(this.baseRange.depTypeRange, defaultDepType);
				var obj = this.getSelectRangeItem(this.baseRange.depTypeRange, this.baseFormData.operateDept);
				if (obj != undefined) {
					this.baseFormData.deptName = obj.text;
				}
				//获取出入库默认类型类型
				var defaultRdStyle = await configJs.getBaseInfo.getDefaultRdStyle()
				//获取出库类型信息
				var type = 0;
				this.baseRange.sdTypeRange = await configJs.getBaseInfo.getRdStyle({
					inOutType: this.pageCode,
					dFlag: type
				})
				this.baseFormData.typeCode = this.selectFirstRage(this.baseRange.sdTypeRange, defaultRdStyle,
					"happen");
				//获取入库类型信息
				var type = 1;
				// var type = 0;
				this.baseRange.targetSdTypeRange = await configJs.getBaseInfo.getRdStyle({
					inOutType: this.pageCode,
					dFlag: type
				})
				this.baseFormData.targetTypeCode = this.selectFirstRage(this.baseRange.targetSdTypeRange,
					defaultRdStyle, "target");
				await this.getTemCodeInfo();
			},
			/**
			 * 获取基础信息下拉框默认选中项
			 * @param {Object} rage1
			 * @param {Object} rage2
			 */
			selectFirstRage(rage1, rage2, type = "") {
				var item = "";
				var flag = false;
				if (rage2 != undefined && rage2.length > 0) {
					rage2.forEach((obj, index) => {
						if (obj.value == undefined || obj.value.length <= 0) {
							if (!flag) {
								item = SystemJs.systemJs.selectFirstRage(rage1, 0)
							}
						} else {
							var arr = obj.code.split('_');
							var temCode = arr[0];
							if (temCode == this.pageCode) {
								if (obj.code.indexOf("Rd_Style") != -1 || obj.code.indexOf("Ware_Style") != -1) {
									if (!SystemJs.systemJs.IsEmpty(type)) {
										var value = JSON.parse(obj.value);
										var select = SystemJs.systemJs.selectRage(rage1, value[type])
										console.log(value[type])

										if (select) {
											item = value[type];

										}
										console.log(obj.code + "”" + item)

									}
								} else {
									var select = SystemJs.systemJs.selectRage(rage1, obj.value)
									if (select) {
										item = obj.value;

									}
								}
							} else if (obj.code.indexOf('all') != -1) {
								var select = SystemJs.systemJs.selectRage(rage1, obj.value)
								if (select) {
									item = obj.value;
								}
							}
						}
					})
					if (SystemJs.systemJs.IsEmpty(item)) {
						//默认选择第一个账套
						item = SystemJs.systemJs.selectFirstRage(rage1, 0)
						return item;
					}
				} else {
					//默认选择第一个账套
					item = SystemJs.systemJs.selectFirstRage(rage1, 0)
					return item;
				}
				return item;
			},

			/**
			 * 获取选中临时编码后自动初始化下拉框选择信息
			 */
			getSelectTempInfo(obj) {
				if (obj != undefined && obj.tempCode != undefined) {
					//初始化发生仓库信息
					if (!SystemJs.systemJs.IsEmpty(obj.wareHouse)) {
						this.baseFormData.wareHouse = obj.wareHouse;
						this.getGoodsPosition(this.baseFormData.wareHouse,obj.goodsPosition)
					}
					//初始化目标仓库信息
					if (!SystemJs.systemJs.IsEmpty(obj.targetWareHouse)) {
						this.baseFormData.targetWareHouse = obj.targetWareHouse;
						this.getTargetGoodsPosition(this.baseFormData.targetWareHouse,obj.targetGoodsPosition)
					}
					// //初始化货位信息
					// if (!SystemJs.systemJs.IsEmpty(obj.goodsPosition)) {
					// 	this.baseFormData.goodsPosition = obj.goodsPosition;
					// }
					// //初始化货位信息
					// if (!SystemJs.systemJs.IsEmpty(obj.targetGoodsPosition)) {
					// 	this.baseFormData.targetGoodsPosition = obj.targetGoodsPosition;
					// }
					//初始化部门信息
					if (!SystemJs.systemJs.IsEmpty(obj.operateDept)) {
						this.baseFormData.operateDept = obj.operateDept;
					}
					//初始化部门信息
					if (!SystemJs.systemJs.IsEmpty(obj.deptName)) {
						this.baseFormData.deptName = obj.deptName;
					}
					//初始化出库类型信息
					if (!SystemJs.systemJs.IsEmpty(obj.typeCode)) {
						this.baseFormData.typeCode = obj.typeCode;
					}
					//初始化入库类型信息
					if (!SystemJs.systemJs.IsEmpty(obj.targetTypeCode)) {
						this.baseFormData.targetTypeCode = obj.targetTypeCode;
					}
					//初始化发生日期信息
					if (!SystemJs.systemJs.IsEmpty(obj.happenDate)) {
						this.baseFormData.happenDate = obj.happenDate;
					}
					//初始化单据类型信息
					if (!SystemJs.systemJs.IsEmpty(obj.isBlue)) {
						this.baseFormData.isBlue = obj.isBlue;
					}
					this.baseDisabled = true;
				} else {
					this.baseDisabled = false;
				}
			},
			getFocus() {
				this.scanFouce = true;
			},
			/**
			 * 新增临时单据编码
			 */
			async addTempCode() {
				var obj = {};
				var scanType = {
					types: '',
					memo: ''
				};
				scanType.types = 'DB';
				scanType.memo = '调拨单号';

				var timeStr = await configJs.getBaseInfo.addTempCode(scanType)
				// var timeStr = SystemJs.systemJs.getDateTimeStr();
				obj.value = timeStr;
				obj.text = timeStr;
				//第一个参数（插入位置），第二个参数（0），第三个参数（插入的项）
				this.baseRange.tempCodeRange.splice(0, 0, obj);
				this.baseFormData.tempCode = timeStr;
				this.baseDisabled = false;
				this.baseFormData.outOrderCode = "";
				this.baseFormData.customCode = "";
			},
			/**
			 * 删除临时编码
			 */
			delTempCode() {
				var obj = {};
				obj.tempCode = this.baseFormData.tempCode
				obj.inOutType = this.pageCode;
				SystemJs.httpUnit.requestCryptoPost({
					url: 'App/DeleteScanRecord',
					data: obj
				}).then((res) => {
					if (res.Result) {
						this.getTemCodeInfo();
					} else {
						SystemJs.httpUnit.uniToast(res.Message)
					}
				}).catch((err) => {
					SystemJs.httpUnit.uniToast(JSON.stringify(err))
				})
			},
			///悬浮按钮中菜单点击事件
			fadTrigger(e) {
				console.log(e);
				var target = e.item;
				if (target != undefined) {
					/**
					 * 新增临时单据编码
					 */
					if (target.code == "add") {
						console.log('add');
						this.addTempCode();
					}
					/**
					 * 删除临时单据编码
					 */
					if (target.code == "del") {
						console.log('del');
						console.log('del', this.baseFormData.tempCode);
						if (SystemJs.systemJs.IsEmpty(this.baseFormData.tempCode)) {
							uni.showToast({
								icon: 'error',
								title: '请先选择临时编码'
							})
						} else {
							var obj = SystemJs.showDialog.dialogInfo
							obj.msgType = "warn";
							obj.title = "提示";
							obj.content = "是否确认删除单据？";
							obj.cancel = true;
							obj.confirm = true;
							obj.dialogConfirm(() => {
								console.log('用户点击确定');
								this.delTempCode();
							})
							obj.dialogClose(() => {

							})
							SystemJs.showDialog.openDialog(this.$refs.alertDialog, obj)
						}
					}
					/**
					 * 保存单据
					 */
					if (target.code == "save") {
						this.saveTempScanInfo();
					}
				}
			},
			//列表滑动时的监听事件(改变顶部汇总信息栏的背景透明度)
			listScroll(e) {
				// console.log(e);
				var listTop = e.detail.scrollTop; //距离顶部的长度
				if (listTop >= this.listSumHeight) {
					this.opacityValue = 1;
					this.showListSum = true;
				} else {
					//透明度
					this.opacityValue = (listTop / this.listSumHeight) * 1.7
					this.showListSum = false;
				}
			},
			/**
			 * swiperView滑动到底部监听事件
			 * @param {Object} e
			 */
			scrolltolower(e) {
				console.log("滚动到底部");
				this.loadMore = false;
				if (this.page >= this.sumPages) {
					this.loadStaus = "noMore";
				} else {
					this.loadStaus = "loading";
					// this.page++;
					var page = this.page + 1;
					var timeout = setTimeout(() => {
						this.getListInfo(false, page);
						clearTimeout(timeout);
					}, 1000)
				}
				this.loadMore = true;
			},
			//获取列表内容中每行的个数
			getListContent(content) {
				var count = 0;
				if (content.length > 0) {
					count = 24 / content.length
				}
				return count;
			},
			//手动切换界面
			changeSwiper(e) {
				console.log('e', e)
				this.currentIndex = e.detail.current;
				if (this.currentIndex == 1) {
					this.getListInfo();
				}
				//动态设置swiper的高度，使用nextTick延时设置
				this.$nextTick(() => {
					// this.setSwiperHeight();
				});
			},

			//打开日期选择器
			open() {
				this.$nextTick(() => {
					this.$refs.startDate.open();
				})
			},
			//选择日期确认事件
			confirm(e) {
				console.log(e);
				try {
					this.baseFormData.happenDate = e.fulldate
				} catch (e) {
					console.log(e);
				}
			},
			//红蓝单据类型选择事件
			change(e, type) {
				if (!SystemJs.systemJs.IsEmpty(type)) {
					if (type == 'dept') {
						var obj = this.getSelectRangeItem(this.baseRange.depTypeRange, e);
						if (obj != undefined) {
							this.baseFormData.deptName = obj.text;
						}
					}
					if (type == 'temp') {
						var obj = this.getSelectRangeItem(this.baseRange.tempCodeRange, e);
						console.log(obj)
						if (obj != undefined) {
							this.getSelectTempInfo(obj);
						}
					}
					if (type == 'ware') {
						this.getGoodsPosition(e)
					}
					if (type == 'targetWare') {
						this.getTargetGoodsPosition(e)
					}
				}
				if (this.baseFormData.isBlue == 1) {
					this.selectedColor = 'blue'
				} else {
					this.selectedColor = 'red'
				}
			},
			//获取下拉框选中的对象
			getSelectRangeItem(range, value) {
				var obj = undefined;
				if (range != undefined && range.length > 0) {
					obj = range.find((item) => item.value == value)
				}
				return obj;
			},
			close(e) {
				console.log("e:", e);
			},
			//点击收缩面板事件
			collapseChage(e) {
				// if(e.length>0){
				// 	this.scanFouce=true;
				// }else{
				// 	this.scanFouce=false;
				// }
				console.log("e:", e);
				console.log("collapseList", this.collapseList);
			},
			/**
			 * 判定扫描条码是否正确
			 * @param {Object} flag
			 */
			checkBarCodeRight(flag) {
				if (flag) {
					SystemJs.ScanAudio.playRight();
				} else {
					SystemJs.ScanAudio.playError();
					//长震动
					uni.vibrateLong({
						success: () => {
							console.log('succ', 'success')
						}
					})
					return;
				}
			},
			//回车事件
			scanInput(e) {
				this.scanFouce = false;
				this.$nextTick(() => {
					this.scanFouce = true;
				});

				if (SystemJs.systemJs.IsEmpty(this.scanBarCode)) {
					SystemJs.ScanAudio.playError();
					//长震动
					uni.vibrateLong({
						success: () => {
							console.log('succ', 'success')
						}
					})
					return;
				}
				console.log("e:", e);
				// SystemJs.ScanAudio.playRight();
				this.addTempScanInfo();
				// uni.pageScrollTo({
				// 	scrollTop: 0,
				// 	duration: 0
				// })
			},
			//点击扫描按钮
			iconClick(type) {
				SystemJs.unitJs.scanBarCode({
					success: (res) => {
						this.scanBarCode = res.result;
						this.addTempScanInfo();
						console.log("e:", res.result);
					},
					fail: (err) => {
						console.log("e:", err);
						SystemJs.httpUnit.uniToast(JSON.stringify(err));
					}
				})

				// uni.scanCode({
				// 	scanType: ['barCode', 'qrCode'],
				// 	success: (res) => {
				// 		this.scanBarCode = res.result;
				// 		this.addTempScanInfo();
				// 		console.log("e:", res.result);
				// 	},
				// 	fail: (err) => {
				// 		console.log("e:", err);
				// 		SystemJs.httpUnit.uniToast(JSON.stringify(err));
				// 	}
				// })
				// uni.showToast({
				// 	title: `点击了图标`,
				// 	icon: 'none'
				// })
			},
			/**
			 * 添加扫描的条码信息
			 */
			addTempScanInfo() {
				var obj = {};
				//判断信息是否都选择
				if (SystemJs.systemJs.IsEmpty(this.scanBarCode)) {
					SystemJs.httpUnit.uniToast("请先扫描条码号")
					return;
				}
				if (SystemJs.systemJs.IsEmpty(this.baseFormData.tempCode)) {
					SystemJs.httpUnit.uniToast("请先选择临时编码")
					return;
				}
				if (SystemJs.systemJs.IsEmpty(this.baseFormData.wareHouse)) {
					SystemJs.httpUnit.uniToast("请先选择发生仓库")
					return;
				}
				if (this.baseRange.goodsPositionRange != undefined && this.baseRange.goodsPositionRange > 0) {
					// if (SystemJs.systemJs.IsEmpty(this.baseFormData.goodsPosition)) {
					// 	SystemJs.httpUnit.uniToast("请先选择发生货位")
					// 	return;
					// }
				}
				if (SystemJs.systemJs.IsEmpty(this.baseFormData.targetWareHouse)) {
					SystemJs.httpUnit.uniToast("请先选择目标仓库")
					return;
				}
				if (SystemJs.systemJs.IsEmpty(this.baseFormData.operateDept)) {
					SystemJs.httpUnit.uniToast("请先选择发生部门")
					return;
				}
				if (SystemJs.systemJs.IsEmpty(this.baseFormData.typeCode)) {
					SystemJs.httpUnit.uniToast("请先选择出库类型")
					return;
				}
				if (SystemJs.systemJs.IsEmpty(this.baseFormData.targetTypeCode)) {
					SystemJs.httpUnit.uniToast("请先选择入库类型")
					return;
				}
				if (SystemJs.systemJs.IsEmpty(this.baseFormData.happenDate)) {
					SystemJs.httpUnit.uniToast("请先选择发生日期")
					return;
				}
				if (SystemJs.systemJs.IsEmpty(this.baseFormData.isBlue)) {
					SystemJs.httpUnit.uniToast("请先选择单据类型")
					return;
				}
				// if (this.pageCode) {
				// 	if (this.pageCode.indexOf('cp') > 0) {
				// 		//成品入库不需要传目标货位
				// 		this.baseFormData.targetGoodsPosition = "";
				// 	}
				// }
				obj = this.baseFormData;
				obj.barCode = this.scanBarCode;
				obj.baseCode = uni.getStorageSync('account');
				obj.operateType = this.pageType;
				obj.inOutType = this.pageCode;
				obj.barcodeNumber = 1;
				var createuser = '';
				if (this.userInfo.userCode) {
					createuser = this.userInfo.userCode;
				}
				obj.createuser = createuser;
				console.log(JSON.stringify(obj))
				SystemJs.httpUnit.requestCryptoPost({
					url: 'App/AddScanRecord',
					data: obj
				}).then((res) => {
					if (res.Result) {
						var obj = res.Data;
						if (obj && obj.barNumber) {
							this.scanNumber = obj.barNumber;
						}
						this.getBarCodeInfo(this.scanBarCode, '扫描成功');
						this.checkBarCodeRight(true);
						this.scanBarCode = "";
					} else {
						var message = res.Message;

						if (!SystemJs.systemJs.IsEmpty(message)) {
							if (message.indexOf('已扫描') != -1) {
								var obj = SystemJs.showDialog.dialogInfo
								obj.msgType = "warn";
								obj.title = "提示";
								obj.content = "是否要删除该条码？";
								obj.cancel = true;
								obj.confirm = true;
								obj.dialogConfirm(() => {
									this.delTempScanInfo();
								})
								obj.dialogClose(() => {
									this.scanBarCode = "";
								})
								SystemJs.showDialog.openDialog(this.$refs.alertDialog, obj)
							} 
							else {
								SystemJs.httpUnit.uniToast(res.Message)
							}
						}
						this.checkBarCodeRight(false);
					}
				}).catch((err) => {
					SystemJs.httpUnit.uniToast(JSON.stringify(err))
				})
			},
			/**
			 * 删除扫描的条码信息
			 */
			delTempScanInfo() {
				if (SystemJs.systemJs.IsEmpty(this.scanBarCode)) {
					SystemJs.httpUnit.uniToast("请先扫描条码号")
					return;
				}
				if (SystemJs.systemJs.IsEmpty(this.baseFormData.tempCode)) {
					SystemJs.httpUnit.uniToast("请先选择临时编码")
					return;
				}
				var obj = {};
				obj.tempCode = this.baseFormData.tempCode;
				obj.barCode = this.scanBarCode;
				obj.mobType = 'H5';
				SystemJs.httpUnit.requestCryptoPost({
					url: 'App/DeleteScanBarCode',
					data: obj
				}).then((res) => {
					if (res.Result) {
						var obj = res.Data;
						if (obj && obj.barNumber) {
							this.scanNumber = obj.barNumber;
						}
						this.getBarCodeInfo(this.scanBarCode, '删除成功');
						this.scanBarCode = "";
					} else {
						SystemJs.httpUnit.uniToast(res.Message)
					}
				}).catch((err) => {
					SystemJs.httpUnit.uniToast(JSON.stringify(err))
				})
			},
			/**
			 * 获取条码信息
			 * @param {Object} barCode
			 */
			getBarCodeInfo(barCode, memo) {
				var obj = {};
				obj.barCode = this.scanBarCode;
				obj.baseCode = uni.getStorageSync('account');
				obj.inOutType = this.pageCode;
				SystemJs.httpUnit.requestCryptoPost({
					url: 'App/GetScanBarCode',
					data: obj
				}).then((res) => {
					if (res.Result) {
						var info = "";
						info = info + memo + '\n';
						var list = res.Data;
						if (list != undefined && list.length > 0) {
							var scanList = list[0].scanList;
							if (scanList != undefined && scanList.length > 0) {
								var head = scanList[0];
								var body = scanList[1];
								for (let key in head) {
									info = info + head[key] + ":" + body[key] + '\n'
								}
							}
						}
						this.returnMessage = info;
					} else {
						SystemJs.httpUnit.uniToast(res.Message)
					}
				}).catch((err) => {
					SystemJs.httpUnit.uniToast(JSON.stringify(err))
				})
			},
			/**
			 * 保存临时扫描单据
			 */
			saveTempScanInfo() {
				if (SystemJs.systemJs.IsEmpty(this.baseFormData.tempCode)) {
					SystemJs.httpUnit.uniToast("请先选择临时编码")
					return;
				}
				SystemJs.unitJs.noMultipleClicks(this, () => {
					var obj = {};
					obj.tempCode = this.baseFormData.tempCode;
					obj.operateType = this.pageType;
					obj.baseCode = uni.getStorageSync('account');
					obj.inOutType = this.pageCode;
					var createuser = '';
					if (this.userInfo.userCode) {
						createuser = this.userInfo.userCode;
					}
					obj.createuser = createuser;
					SystemJs.httpUnit.requestCryptoPost({
						url: 'App/SaveTmpeCode',
						data: obj,
						isLoading: true
					}).then((res) => {
						if (res.Result) {
							var info = "";
							info = info + res.Data;
							if (!SystemJs.systemJs.IsEmpty(res.Message)) {
								info = info + res.Message;
							}

							this.returnMessage = info;
							this.scanNumber = 0;
							// this.getListInfo();
							this.clearListInfo();
							this.getTemCodeInfo();
							SystemJs.httpUnit.uniToast(info);
							// var timeout = setTimeout(() => {
							// 	SystemJs.httpUnit.uniToast(info);
							// 	clearTimeout(timeout);
							// }, 1000)

						} else {
							this.returnMessage = res.Message;
							SystemJs.httpUnit.uniToast(res.Message)
						}
					}).catch((err) => {
						SystemJs.httpUnit.uniToast(JSON.stringify(err))
					})
				})
			},
			/**
			 * 获取扫描列表信息
			 */
			getListInfo(isFirst = true, pageIndex = 1) {
				if (isFirst) {
					this.clearListInfo();
				}
				var obj = {};
				obj.tempCode = this.baseFormData.tempCode;
				obj.operateType = this.pageType;
				obj.baseCode = uni.getStorageSync('account');
				obj.inOutType = this.pageCode;
				obj.mobType = "H5";
				obj.pageIndex = pageIndex;
				SystemJs.httpUnit.requestCryptoPost({
					url: 'App/GetInputList',
					data: obj
				}).then((res) => {
					if (res.Result) {
						var obj = res.Data;
						this.sumPages = Number(obj.listInfo.pageNumber);
						this.page = Number(obj.listInfo.pageIndex);
						this.headInfo = obj.listInfo.head;
						this.barMxHeadData = obj.listInfo.mxHead;
						if (!isFirst) {
							this.scanBarListInfo = this.scanBarListInfo.concat(obj.listInfo.list);
							this.barMxListData = this.barMxListData.concat(obj.listInfo.mxList);
						} else {
							this.scanBarListInfo = obj.listInfo.list;
							this.barMxListData = obj.listInfo.mxList;
						}
						this.sumHeadData = obj.sumList.head;
						this.sumListData = obj.sumList.list;
						this.loadStaus = "noMore";
					} else {
						SystemJs.httpUnit.uniToast(res.Message)
						this.clearListInfo();
					}
				}).catch((err) => {
					SystemJs.httpUnit.uniToast(JSON.stringify(err))
				})
			},
			/**
			 * 清除列表字段信息
			 */
			clearListInfo() {
				this.listSumHeight = 0;
				this.listInfo = [];
				this.sumList = [];
				this.loadMore = true;
				this.loadStaus = "noMore";
				this.page = 1;
				this.sumPages = 1;
				this.scanBarListInfo = [];
				this.barMxListData = [];
				this.sumHeadData = [];
				this.sumListData = [];
				this.headInfo = [];
				this.barMxHeadData = [];
			},
			/**
			 * 创建列表item元素的显示格式
			 * @param {Object} headList
			 * @param {Object} list
			 */
			createListItemInfo(headList, list) {
				var listInfo = [];
				if (list != undefined && list.length > 0) {
					for (var i = 0; i < list.length; i++) {
						var itemObj = {};
						var itemList = [];
						var item = list[i] //每个item信息
						if (headList != undefined && headList.length > 0) {
							for (var r = 0; r < headList.length; r++) {
								var row = headList[r];
								var rowObj = {};
								var rowList = [];
								if (row != undefined && row.length > 0) {
									for (var c = 0; c < row.length; c++) {
										var col = row[c];
										var colObj = {};
										if (!SystemJs.systemJs.IsEmpty(col.type)) {
											colObj.type = col.type;
										}
										colObj.title = col.name;
										colObj.value = item[col.code];
										rowList.push(colObj);
									}
								}
								rowObj.content = rowList;
								itemList.push(rowObj);
							}
						}
						itemObj.list = itemList;
						listInfo.push(itemObj);
					}
				}
				return listInfo;
			},

			submit() {
				this.buttonLoading = true

				var timeoutID = setTimeout(() => {
					uni.showToast({
						title: `点击了图标`,
						icon: 'none'
					})
					this.buttonLoading = false
					clearTimeout(timeoutID)
				}, 2000)
			},
			///打开参照列表
			openCommon() {
				var title = "销售订单";
				uni.navigateTo({
					url: `/pages/business/CommonInfo?pageCode=${this.pageCode}&pageType=${this.pageType}&title=${title}`,
					success: (res) => {
						res.eventChannel.emit('commData', {
							page: '01'
						})
					}
				});
				//监听该事件是否被触发，此方法只监听一次
				uni.$once('saveData', this.updateSaveData)
			},
			updateSaveData(res) {
				// if (this.pageCode == "pos" && res.value != undefined) {
				// 	this.baseFormData.outOrderCode = res.value[0].cDLCode;
				// }
				// console.log('监听到事件来自 update ，携带参数 msg 为：' + res.code);
			}
		}
	}
</script>

<style scoped>
	/* movable-area {
		width: 100%;
		background-color: #D8D8D8;
		overflow: hidden;
	} */

	/* 	movable-view {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 150rpx;
		width: 150rpx;
		background-color: #007AFF;
		color: #fff;
	}
 */
	.uni-scroll-view,
	.uni-scroll-view-content {
		width: 100%;
		height: 100%;
	}

	.content {
		padding: 15px;
	}

	.form-item {
		display: flex;
		align-items: center;
	}


	.fad-view {
		height: 20px;
		width: 10px;
		overflow: hidden;
	}

	.fad-style {
		height: 20px;
		width: 20px;
	}

	.tab-view {
		flex: 1;
	}

	.uni-column {
		display: flex;
		flex-direction: column;
	}


	/* 	.swiper {
		height: 100vh;
	} */

	/* 	.swiper-item {
		height: 100vh;
	} */

	/* 页面可滚动 */
	.scroll-Y {
		flex: auto;
		overflow: auto;
	}

	.fixedTop {
		position: fixed;
		width: 100%;
		top: 0;
		left: 0;
		z-index: 999;
		background-color: #fff;
	}

	/* 修改form表单列样式 缩小间距*/
	.uni-forms-item {
		margin-bottom: 0px;
	}

	/* 我们需要在 style 标签上加 scoped，同时使用 deep 穿透  才能修改覆盖了子组件的样式，否则无法在父组件中修改子组件样式*/
	/deep/ .uni-forms-item.is-direction-top .uni-forms-item__label {
		padding: 0px;
	}

	/* 修改输入框不可编辑时的样式 */
	/deep/.is-disabled {
		color: #666666;
	}
</style>